import pandas as pd

""" 函数	说明
df.sort_values(column_name)	按照指定列的值排序；
df.sort_values([column_name1, column_name2], ascending=[True, False])	按照多个列的值排序；
"""

data = {
    "Name": ["Alice", "Bob", "Tom", "Jerry", "David"],
    "Age": [22, 23, 24, 25, 26],
    "City": ["Beijing", "Shanghai", "Guangzhou", "Shenzhen", "Hangzhou"],
}
df = pd.DataFrame(data)

# 1.指定列排序
sort_name = df.sort_values(by="Name")  # 正序
re_sort_age = df.sort_values(by="Age", ascending=False)  # 倒序
re_index = df.sort_index()  # 按索引排序
print("按 name 正序:\n", sort_name)
print("按 age 倒序:\n", re_sort_age)
print("重新 排序索引:\n", re_index)
""" 
按 name 正序:
     Name  Age       City
0  Alice   22    Beijing
1    Bob   23   Shanghai
4  David   26   Hangzhou
3  Jerry   25   Shenzhen
2    Tom   24  Guangzhou

按 age 倒序:
     Name  Age       City
4  David   26   Hangzhou
3  Jerry   25   Shenzhen
2    Tom   24  Guangzhou
1    Bob   23   Shanghai
0  Alice   22    Beijing

重新 排序索引:
     Name  Age       City
0  Alice   22    Beijing
1    Bob   23   Shanghai
2    Tom   24  Guangzhou
3  Jerry   25   Shenzhen
4  David   26   Hangzhou
"""
